<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
//use Swoole\chan;
use Swoole\Coroutine\Channel as chan;

class CoChan extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'co:chan';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $chan=new chan(4);
        go(function()use($chan){
            $result=[];
            for($i=0;$i<4;$i++){
                    $result[]=$chan->pop();
            }
            var_dump($result);
        });

        go(function()use($chan){
            $chan->push(['name'=>'xiaoming']);
        });

        go(function()use($chan){
            $chan->push(['name'=>'kangkang']);
        });

        go(function()use($chan){
            $chan->push(['name'=>'zjh']);
        });

        
    }
}
